n = (input())
if len(n) != 4:
    print(0)
else:
    ls = []
    for x in range(4):
        txt = ''
        for i in range(4):
            try:
                txt = txt + n[i+x]
                ls.append(int(txt))
            except:
                pass

    

    ls_f = []
    for i in ls:
        s = i
        x = 0
        while s >=1:
            i % s
            if i != s and s != 1 and i%s == 0:
                x = 1
            s -= 1
        if x == 0:
            
            ls_f.append(i)

    if len(ls_f) > 0:
        print(sorted(ls_f,reverse=True)[0])
    else:
        print()
    
